package userinterface;

import java.util.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.*;

public class StudentManager {

    public class Student {
        public class Student {
            private String id;
            private String name;

            public Student() {

            }

            public Student(String id, String name) {
                this.id = id;
                this.name = name;
            }

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }
        }
    }

    public static void main(String[] args) {

        ArrayList<Student> list = new ArrayList<>();

        JFrame win = new JFrame("学生管理系统");
        win.setSize(500, 500);
        win.setVisible(true);
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setLayout(new GridLayout(0, 1));

        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();

        JLabel l1 = new JLabel("欢迎来到学生管理系统");
        p1.add(l1);

        JButton b1 = new JButton("录入学生成绩");
        b1.addActionListener((e) -> {
            InputUserInfo(e, list);
        });
        JButton b2 = new JButton("显示学生信息");
        b2.addActionListener((e) -> {
            QueryInfro(e, list);
        });
        p2.add(b1);
        p2.add(b2);
        win.add(p1);
        win.add(p2);
    }

    public static void InputUserInfo(ActionEvent e, ArrayList<Student> list) {
        Student stu = new Student();

        JFrame newf1 = new JFrame("学生信息录入");
        newf1.setLayout(new GridLayout(0, 1));
        newf1.setSize(500, 500);

        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();

        newf1.add(p1);
        newf1.add(p2);

        JTextField t1_1 = new JTextField(16);
        p1.add(new JLabel("学号"));
        p1.add(t1_1);

        JTextField t1_2 = new JTextField(16);
        p1.add(new JLabel("姓名"));
        p1.add(t1_2);

        String id = t1_1.getText();
        stu.setId(id);
        String name = t1_2.getText();
        stu.setName(name);

        newf1.setVisible(true);
    }

    public static void QueryInfro(ActionEvent e, ArrayList<Student> list) {
        JFrame newf2 = new JFrame("学生信息查询");
        newf2.setLayout(new GridLayout(0, 1));
        newf2.setSize(500, 500);

        JPanel P1 = new JPanel();
        JPanel p2 = new JPanel();

        p1.add(new JLabel("id\t\t姓名"));
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            p2.add(new JLabel(stu.getId() + "\t" + stu.getName()));

            newf2.setVisible(true);
        }

    }
}